<script type="text/javascript">

    $(function(){
        $('a, .fa-star').tooltip();
        $('button.btn').tooltip({container:'body'});

        $('#gridRefresh').click(function(e){
            $.fn.yiiGridView.update("menu-grid");
        });

        //Отправляем ajax запрос серверу,
        //Для установки главной страницы
        $('.fa-star').live('click',function(e){

            var id = $(this).closest('tr').find('td:first input').val();
            $.ajax({
                url:'setmainpage',
                data:{'id':id},
                dataType:'JSON',
                error:function(error){
                    alert('Error Ajax request');
                },
                success:function(resp){
                    $.fn.yiiGridView.update("menu-grid");
                }
            });
        });

        $('#mainPage').live('click',function(e){
            alert($('#mainPageAlert').text());
        });
    });
    function changeStatus(id)
    {

        var el = $('#menu-grid  table  tr');
        el.each(function(i,e){
            var tdId,aId;
            tdId = $(e).find('td:nth-child(2)');
            if(tdId.text() === id)
            {
                aId =  $(tdId).next().find('a#'+id);
                if(aId.attr('class') === 'publish'){
                    aId.attr('class','unpublish').find('i').attr('class','fa fa-times-circle red font22');;
                }
                else{
                    aId.attr('class','publish').find('i').attr('class','fa fa-chevron-circle-down green font22');;
                }
            }
        });
        return true;
    }
</script>
<?php
    $this->pageTitle = Yii::t('MenuModule.base','Menu items');
    $this->breadcrumbs=array(
        Yii::t('MenuModule.base','Menus')=>'index',
        Yii::t('MenuModule.base','Menu manager')=>'admin',
        Yii::t('MenuModule.base','Menu items'),
    );
?>
<?php if(Yii::app()->user->hasFlash('success')):?>
<div class="alert alert-success">
    <a class="close" data-dismiss="alert" href="#" aria-hidden="true">&times;</a>
    <h4><i class="fa fa-info-circle paddingRight10"></i><?php echo Yii::t('MenuModule.base','Message')?></h4>
    <p><?php echo Yii::app()->user->getFlash('success');?></p>
</div>
<?php endif;?>
<div class="panel panel-primary">
    <div class="panel-heading">
        <i class="fa fa-list-ul"></i><span class="h4"><?php echo Yii::t('MenuModule.base','Menu Manager: Menu Items');?></span><?php echo CHtml::link('<i class="fa fa-refresh"></i>','#',array('id'=>'gridRefresh','class'=>'white alignRight','data-toggle'=>'tooltip','title'=>Yii::t('MenuModule.base','Refresh'),'style'=>'padding-right:10px;font-size:18px'))?>
    </div>
    <div class="panel-body">

        <div class="search-form">
            <?php $this->renderPartial('_search',array(
                'model'=>$model,
                'columnName'=>'title'
            )); ?>
        </div><!-- button-group-->
        <div class="btn-group">
            <?php $this->renderPartial('_buttons',array(

            )); ?>
        </div><!-- button-group-->
        <?php $this->widget('zii.widgets.grid.CGridView', array(
            'id'=>'menu-grid',
            'dataProvider'=>$model->search(),
            //'filter'=>$model,
            'pager' => array('cssFile' => Yii::app()->theme->baseUrl . '/assets/gridview/pager.css'),
            'baseScriptUrl'=>Yii::app()->theme->baseUrl.'/assets/gridview',
            'cssFile'=> Yii::app()->theme->baseUrl . '/assets/gridview/styles.css',
            'columns'=>array(
                array(
                    'class'=>'CCheckBoxColumn',
                    'id'=>'autoId',
                    'selectableRows' => 50,
                    'checkBoxHtmlOptions' => array('class' => 'checkbox'),
                    'htmlOptions'=>array('style'=>'width:20px')
                ),
                array(
                    'name' => 'id',
                    'type' => 'raw',
                    'value'=>'CHtml::tag("span",array("class"=>"badge"),$data->id)',
                    'htmlOptions'=>array('style'=>'width:20px')
                ),
                array(
                    'name' => 'status',
                    'type' => 'raw',
                    'value'=>'$data->getAjaxStatus($data->id)',
                ),
                array(
                    'name' => 'title',
                    'type' => 'raw',
                    'value'=>'CHtml::link($data->title,Yii::app()->createUrl("menu/backend/update",array("id"=>"$data->id")))',
                    'htmlOptions'=>array('id'=>$model->id)
                ),
                array(
                    'name' => 'access',
                    'type' => 'raw',
                    'value'=>'$data->getAccessStatus()',

                ),
                'position',
                array(
                    'name' => 'create_time',
                    'type' => 'raw',
                    'value'=>'CHtml::tag("span",array("class"=>"label label-default"),CLocale::getInstance(Yii::app()->getLocale()->id)->dateFormatter->formatDateTime(strtotime($data->create_time),"long","short"))',
                ),
                array(
                    'name' => 'update_time',
                    'type' => 'raw',
                    'value'=>'CHtml::tag("span",array("class"=>"label label-primary"),CLocale::getInstance(Yii::app()->getLocale()->id)->dateFormatter->formatDateTime(strtotime($data->update_time),"long","short"))',
                ),
                array(
                    'name'=>'main',
                    'type'=>'raw',
                    'value'=>'$data->getStar()'
                )
            )));?>

    </div>

        <span id="mainPageAlert" class="hidden"><?php echo Yii::t('MenuModule.base','You can not shoot with the publication of a menu item, the designated "home page"')?></span>

</div>

